 
from selenium import webdriver
from selenium.webdriver.common.by import By  # 导入 By 类

try:
    driver = webdriver.Chrome()
    driver.get("https://www.baidu.com")
    
    # 使用新的定位语法
    search_box = driver.find_element(By.ID, "kw")  # 替换为 By.ID
    if search_box:
        print("元素定位成功！")
        search_box.send_keys("Selenium 验证")
        search_box.submit()
finally:
     driver.quit()